//
//  YGAutoNav.swift
//  SwiftWebo
//
//  Created by 王勇 on 2018/5/28.
//  Copyright © 2018年 Brave. All rights reserved.
//

import UIKit

let isiPhoneX = UIScreen.main.bounds.height == 812

///适配iOS11的导航条上移问题
class YGAutoNav: UINavigationBar {

    override func layoutSubviews() {
        super.layoutSubviews()
        for subview in subviews {
            let subName = NSStringFromClass(subview.classForCoder)
            if subName == "_UIBarBackground" {
                subview.frame = bounds
            }else if subName == "_UINavigationBarContentView" {
                var frame = subview.frame;
                frame.origin.y = isiPhoneX ? 44 : 20
                frame.size.height = self.bounds.size.height - frame.origin.y;
                subview.frame = frame;
            }
        }
    }
}

